const mergeTwoLists = function (list1, list2) {
  const len = list1.length + list2.length;

  let arr1 = 0;
  let arr2 = 0;
  const res = [];
  for (let i = 0; i < len; i++) {
    if (list1[arr1] <= list2[arr2]) {
      res.push(list1[arr1]);
      arr1++;
    } else {
      res.push(list2[arr2]);
      arr2++;
    }
  }
  console.log(res);
  return res;
};
mergeTwoLists([1, 3, 4], [1, 2, 4]);
